package com.mkait.thief.controller;

import com.mkait.thief.bean.vo.BatchRefundVo;
import com.mkait.thief.service.RefundService;
import com.mkait.thief.service.RefundVerifyService;
import com.mkait.thief.util.ResponseWrapper;
import com.mkait.thief.util.WrapResponseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/refund")
@RestController
@Transactional(rollbackFor = Exception.class)
public class RefundController {

    @Autowired
    private RefundService refundService;

    @Autowired
    private RefundVerifyService refundVerifyService;

    @GetMapping("/{trade_no}")
    public ResponseEntity<ResponseWrapper<String>> refund(@PathVariable("trade_no") String tradeNo, @RequestParam("userName") String userName, @RequestParam("password") String password){
        refundService.runRefund(tradeNo);
        return WrapResponseMapper.ok(ResponseWrapper.SUCCESS_MESSAGE);
    }


    @PostMapping("/batchRefund")
    public ResponseEntity<ResponseWrapper<String>> batchRefund(@RequestBody BatchRefundVo vo){
        String userName = vo.getUserName();
        String password = vo.getPassword();
        String[] complaintIds = vo.getIds().split(",");
        refundService.batchRefund(complaintIds);

        return WrapResponseMapper.ok(ResponseWrapper.SUCCESS_MESSAGE);
    }

}
